<template>
  <div class="details-banner">
    <div v-preview="store.getGetPreviewImg()" v-origin="store.state.BaseUrl + details.bg"></div>
    <div class="deatilsInfo">
      <h4>{{ details.title }}</h4>
      <p>
        <span>
          <el-icon :size="12" class="Deatilsicon">
            <Calendar />
          </el-icon>
          &ensp;发表:&ensp;
          {{ dayjs(Number(details.createTime)).format('YYYY-MM-DD HH:mm') }}
        </span>
        <span>
          <el-icon :size="12" class="Deatilsicon">
            <Document />
          </el-icon>
          &ensp;字数统计:&ensp;
          {{ details.info ? setCount(details.info) : 0 }}
        </span>

        <span>
          <el-icon :size="12" class="Deatilsicon">
            <Paperclip />
          </el-icon>
          &ensp;标签:
          <el-tag size="small" effect="plain" type="success" class="tag">
            {{ details.articleType }}</el-tag>
        </span>
      </p>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { inject } from 'vue'
import { Calendar, Document, Paperclip } from '@element-plus/icons-vue'
import dayjs from 'dayjs'

const store: any = inject('store')

// 文章数据
type detailData = {
  _id: string
  title: string
  info: string
  articleType: string
  bg: string
  createTime: string
}
defineProps<{
  details: detailData
}>()
const setCount = (info: string) => {
  let div = document.createElement('div')
  div.innerHTML = info
  // 转换为数组
  let count = [...div.innerText].length
  div.remove()
  return count > 1000 ? (count / 1000).toFixed(2) + ' 千' : count
}
</script>

<style lang="scss" scoped>
.details-banner {
  display: flex;
  position: relative;
  height: 400px;
  width: 100%;
  z-index: -1;
  justify-content: center;
  align-items: center;
  overflow: hidden;

  :deep(.v-progressive-image) {
    width: 100%;
    height: 100%;
  }

  :deep(.pi-origin),
  :deep(.pi-preview) {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  &::after {
    position: absolute;
    bottom: 0;
    top: 0;
    left: 0;
    right: 0;
    content: '';
    background: rgba($color: #000000, $alpha: 0.4);
  }
}

.deatilsInfo {
  position: absolute;
  user-select: none;
  text-align: center;
  color: #fff;
  z-index: 2;

  h4 {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 28px;
    margin: 0 0 20px;
    letter-spacing: 3px;
    font-weight: 700;
  }

  p {
    >span {
      font-size: 12px;
      margin-right: 20px;
      border-right: 2px solid #fff;
      padding: 0 20px;

      &:nth-child(3) {
        border: 0;
      }
    }
  }
}

@media (max-width: 760px) {
  .details-banner {
    height: 200px;
  }

  .deatilsInfo {
    h4 {
      font-size: 18px;
    }

    p {
      >span {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0;
        padding-top: 5px;
        border: 0;
      }
    }
  }
}
</style>
